$(document).ready(function(){

    $(".my-pages").css({"width":$(".pagination").width()+1});

    $("#buyerlogin").click(function(){
        layer.open({
            type:1,
            title:"登录",
            //skin: 'demo-class',
            area:["395px","300px"],
            resize: false,//页面拉伸
            content:$("#loginBox"),
            cancel: function(index, layero){//关闭按钮的回调
                $("#loginBox").css({"display":"none"})
            }
        })
    })

    $("#buyerregister").click(function(){
        layer.open({
            type:1,
            title:"注册",
            area:["395px","350px"],
            resize: false,
            content:$("#registerBox"),
            cancel: function(index, layero){
                $("#registerBox").css({"display":"none"})
            }
        })
    })

    $("#searchbtn").click(function(){
        var searchData = $("#search").val();
        if(searchData){
            window.location.href = "/?search="+searchData;
        }else{
            window.location.href = "/";
        }
    })
})


function Login(){
    var username = $("#InputUsername").val();//获取用户名trim是去掉空格
    var password = $("#InputUserPwd").val();//获取密码
    if(username==""||password==""){
        layer.alert("用户名或者密码不能为空!",{
        title:"提示",
        icon:2, 
        });
    }
}

function Register(){
    var username = $("#Username").val();//获取用户名trim是去掉空格
    var password = $("#UserPwd").val();//获取密码
    var repassword = $("#rePwd").val();
    if(username==""||password==""||repassword==""){
        layer.alert("用户名或者密码不能为空!",{
        title:"提示",
        icon:2, 
        });
    }else if(password!=repassword){
        layer.alert("两次密码不一致",{
        title:"提示",
        icon:2, 
        });
    }
}

function myalert(str){
    if(document.getElementsByClassName("my-alert").length == 0){
        new Promise(function(resolve,reject){
            var odiv = document.createElement("div");
            odiv.className = "my-alert";
            odiv.innerHTML = str;
            document.body.appendChild(odiv);
            resolve(odiv)
        }).then(function(odiv){
            var outtimer = setTimeout(function(){
                odiv.remove();
                clearTimeout(outtimer);
            },1000);
        })
    }
}